import json
import os

import matplotlib.pyplot as plt
import numpy as np


def drawAndSave(data, title, label_X, label_Y, path):
    plt.figure(figsize=(12, 10))

    plt.title(title)
    plt.xlabel(label_X)
    plt.ylabel(label_Y)

    plt.plot([i for i in range(1, len(data)+1)], data)

    plt.savefig(path)


def save_as_json(config, name, obj):
    if isinstance(obj, np.ndarray):
        obj = obj.tolist()

    with open(os.path.join(config["res_json_save_path"], name + '.json'), 'w') as fp:
        json.dump(obj, fp)
